package file;

public class ValueObject {

	private String prefix;
	private String value;
	private final String suffix;

	public ValueObject(String string, char seperator) {
		
		//parse string to get prefix, values (ascii chars >= 33), and suffix (suffix+seperator)
		int valueStartIndex = string.length();
		int valueEndIndex = string.length();
		char[] chars = string.toCharArray();
		boolean isValueStartIndexSet = false;
		for (int i = 0; i < chars.length; i++) {
			if(chars[i] >= 33 && !isValueStartIndexSet){
				valueStartIndex = i;
				isValueStartIndexSet = true;
			}else if(isValueStartIndexSet && chars[i] < 33){
				valueEndIndex = i;
				break;
			}
		}
		this.prefix = string.substring(0, valueStartIndex);
		this.value = string.substring(valueStartIndex, valueEndIndex);
		this.suffix = string.substring(valueEndIndex)+seperator;
	}

	public String getPrefix() {
		return prefix;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getSuffix() {
		return suffix;
	}

	/**
	 * This method can be used if some more stuff needed to be add in front of the value.<br>
	 * newPrefix = givenString+oldPrefix
	 * @param string
	 */
	public void addPrePrefix(String string) {
		this.prefix = string+prefix;
	}
	
	@Override
	public String toString() {
		return prefix+value+suffix;
	}
	
}
